<template>
	<view class="wrap">
		<u-button
		  size="normal"
		  type="success"
		  open-type="getUserInfo"
		  @getuserinfo="wxLogin"
		  icon="weixin-fill"
		  text="微信帐号一键登录"
		>
		</u-button>
		<u-button
		  size="normal"
		  @click="toMobile"
		  icon="phone-fill"
		  iconColor="#fff"
		  color="rgb(107, 191, 216)"
		  text="手机号码登录"
		>
		</u-button>
	</view>
</template>

<script>
import { mapMutations } from 'vuex'
export default {
	props:{
		code:{
			type:String,
			default:''
		}
	},
	data(){
		return{
			
		}
	},
	methods:{
		...mapMutations(['setUserInfo', 'setToken', 'setRefreshToken']),
		async wxLogin (e) {
		  const openData = e.detail
		  const res = await this.$axios.api.wxLogin({
		    code: this.code,
		    user: openData
		  })
		  if (res.code === 200) {
		    this.setUserInfo(res.data)
		    this.setToken(res.wxToken)
		    this.setRefreshToken(res.refreshToken)
		    uni.navigateBack({ delta: 1 })
		  } else {
		    uni.showToast({
		      title: '签名失败',
		      icon: 'error',//error loading none
		      duration: 2000
		    })
		  }
		},
		toMobile () {
		  uni.navigateTo({
		    url: '/subcom-my/Auth/Mobile-login'
		  })
		}
	}
}
</script>

<style lang="scss" scoped>
.wrap{
	width: 100%;
	min-height: 500rpx;
	display: flex;
	flex-direction: column;
	justify-content: space-around;
	align-items: center;
}
</style>
